CC = gcc
RM = rm -f
TARGET = run

WORKSPACE := $(shell cd .. && pwd)

LINK_LIBS = -lpthread -ludev

CFLAGS += -Wall -O3 -std=gnu99
CFLAGS += -I/root/projects/studylinux/code/worker
CFLAGS += -I/root/projects/studylinux/common

TARGET_DEVICE_SCANNER = test_scan_dev
TARGET_DEVICE_MONITOR = test_monitor
TARGET_CONTROLLER_SCANNER = test_scan_ctl

COMMON_OBJS := $(WORKSPACE)/udev/device_reporter.o

DEVICE_SCANNER_OBJS := $(WORKSPACE)/udev/test_scan_dev.o
DEVICE_SCANNER_OBJS += $(WORKSPACE)/udev/device_scanner.o

DEVICE_MONITOR_OBJS  = $(WORKSPACE)/udev/test_monitor.o
DEVICE_MONITOR_OBJS += $(WORKSPACE)/udev/device_monitor.o
DEVICE_MONITOR_OBJS += /root/projects/studylinux/code/worker/worker.o

CONTROLLER_SCANNER_OBJS := $(WORKSPACE)/udev/test_scan_ctl.o
CONTROLLER_SCANNER_OBJS += $(WORKSPACE)/udev/controller_scanner.o


ALL: $(TARGET_DEVICE_SCANNER) $(TARGET_DEVICE_MONITOR) $(TARGET_CONTROLLER_SCANNER)
	@echo "Compile all"
	@echo "============================="

$(TARGET_DEVICE_SCANNER): $(DEVICE_SCANNER_OBJS) $(COMMON_OBJS)
	$(CC) $^ -o $@ $(LINK_LIBS)
	@echo "---------------------------------------------------------------"
	./$(TARGET_DEVICE_SCANNER)

$(TARGET_DEVICE_MONITOR): $(DEVICE_MONITOR_OBJS) $(COMMON_OBJS)
	$(CC) $^ -o $@ $(LINK_LIBS)
	@echo "---------------------------------------------------------------"
	# ./$(TARGET_DEVICE_MONITOR)

$(TARGET_CONTROLLER_SCANNER): $(CONTROLLER_SCANNER_OBJS)
	$(CC) $^ -o $@ $(LINK_LIBS)
	@echo "---------------------------------------------------------------"
	# ./$(TARGET_CONTROLLER_SCANNER)

%.o : %.c
	$(CC) $(CFLAGS) -c $< -o $@

clean:
	$(RM) $(SCAN_OBJS) $(DEVICE_MONITOR_OBJS) $(COMMON_OBJS) $(TARGET_SCAN) $(TARGET_DEVICE_MONITOR)
